import request from '@/utils/request'

export interface Product {
  id?: number;
  name: string;
  category: string;
  price: number;
  stock: number;
  status: string;
  createTime?: string;
}

export interface ApiResponse<T> {
  code: number;
  data: T;
  message: string;
}

// 获取商品列表
export const getProducts = () => {
  return request.get<ApiResponse<Product[]>>('/api/products')
}

// 添加商品
export const addProduct = (data: Product) => {
  return request.post<ApiResponse<Product>>('/api/product', data)
}

// 更新商品
export const updateProduct = (data: Product) => {
  return request.put<ApiResponse<Product>>(`/product/${data.id}`, data)
}

// 删除商品
export const deleteProduct = (id: number) => {
  return request.delete<ApiResponse<null>>(`/product/${id}`)
} 